<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('通知模板管理')}" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="template-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                模板名称：<input type="text" name="templateName"/>
                            </li>
                            <li>
                                模板编码：<input type="text" name="templateCode"/>
                            </li>
                            <li>
                                模板类型：<select name="templateType">
                                    <option value="">所有</option>
                                    <option value="1">系统通知</option>
                                    <option value="2">业务通知</option>
                                    <option value="3">公告</option>
                                    <option value="4">提醒</option>
                                </select>
                            </li>
                            <li>
                                状态：<select name="status">
                                    <option value="">所有</option>
                                    <option value="1">启用</option>
                                    <option value="0">禁用</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editFull()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="previewTemplate()">
                    <i class="fa fa-eye"></i> 预览
                </a>
            </div>
            
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    
    <th:block th:insert="~{include :: footer}" />
    
    <script type="text/javascript">
        var prefix = ctx + "message/template";
        
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "模板",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'templateId',
                    title: '模板ID'
                },
                {
                    field: 'templateName',
                    title: '模板名称'
                },
                {
                    field: 'templateCode',
                    title: '模板编码'
                },
                {
                    field: 'templateType',
                    title: '模板类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var typeMap = {'1': '系统通知', '2': '业务通知', '3': '公告', '4': '提醒'};
                        return typeMap[value] || value;
                    }
                },
                {
                    field: 'title',
                    title: '模板标题'
                },
                {
                    field: 'sendMethod',
                    title: '发送方式',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var methodMap = {'1': '站内信', '2': '邮件', '3': '短信', '4': '微信'};
                        return methodMap[value] || value;
                    }
                },
                {
                    field: 'priority',
                    title: '优先级',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var priorityMap = {'1': '低', '2': '中', '3': '高', '4': '紧急'};
                        return priorityMap[value] || value;
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return value == 1 ? '<span class="badge badge-success">启用</span>' : '<span class="badge badge-danger">禁用</span>';
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.templateId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.templateId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="previewTemplate(\'' + row.templateId + '\')"><i class="fa fa-eye"></i>预览</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        // 预览模板
        function previewTemplate(templateId) {
            var url = templateId ? prefix + "/preview/" + templateId : prefix + "/preview";
            $.modal.openFull("模板预览", url);
        }
    </script>
</body>
</html>